﻿/*********************************************************************************************************/
/**
 * mp3 plugin for CKEditor 3.x (Author: TinLT ; Email: tinlt@gsoft.com.vn)
 * version:	 1.0
 * Released: On 14/02/2011
 */
/*********************************************************************************************************/

CKEDITOR.plugins.add('mp3',   
  {    
    requires: ['dialog'],
	lang : ['en'], 
    init:function(a) { 
	var b="mp3";
	var c=a.addCommand(b,new CKEDITOR.dialogCommand(b));
		c.modes={wysiwyg:1,source:0};
		c.canUndo=false;
	a.ui.addButton("mp3",{
					label:a.lang.mp3.title,
					command:b,
					icon:this.path+"mp3.png"
	});
	//CKEDITOR.dialog.add(b,this.path+"dialogs/mp3.js")
	var path = this.path.replace(/ClientScript.*/, '');
	CKEDITOR.dialog.add("mp3",function(e){	
	return{
		title:e.lang.mp3.title,
		resizable : CKEDITOR.DIALOG_RESIZE_BOTH,
		minWidth:180,
		minHeight:40,
		onShow:function(){ 
		},
		onLoad:function(){ 
				dialog = this; 
				this.setupContent();
		},
		onOk:function(){
			var sInsert=this.getValueOf('info','insertcode_area');  			
			if ( sInsert.length > 0 ) 
			{
				var result = "<embed type='application/x-shockwave-flash' flashvars='audioUrl=" + path + sInsert.replace('/', '') + "' src='http://www.google.com/reader/ui/3523697345-audio-player.swf' width='400' height='27' quality='best'></embed>";
				e.insertHtml(result);
			}
		},
		contents:[
			{	id:"info",
				name:'info',
				label:e.lang.mp3.commonTab,
				elements:[{
				 type:'vbox',
				 padding:0,
				 children:[
				  {type:'html',
				  html:'<span>'+e.lang.mp3.HelpInfo+'</span>'
				  },
				  { type:'text',
				    id:'insertcode_area',
					label:''
				  },
				{
					type : 'button',
					id : 'browse',
					filebrowser : 'info:insertcode_area',
					hidden : true,
					// v-align with the 'src' field.
					// TODO: We need something better than a fixed size here.
					style : 'display:inline-block;margin-top:10px;',
					label : e.lang.mp3.BrowseServer
				}]
				}]
			}
		]
	};
});
  }
});